<template>
  <div class="app-container">

    <el-row :gutter="20">
      <el-col :span="8">
        <div class="grid-content bg-purple">
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="原始id" prop="priId">
              <el-input v-model="form.priId" placeholder="请输入原始id"/>
            </el-form-item>
            <el-form-item label="公众号id" prop="appId">
              <el-input v-model="form.appId" placeholder="请输入公众号id"/>
            </el-form-item>
            <el-form-item label="密钥" prop="secret">
              <el-input v-model="form.secret" placeholder="请输入密钥"/>
            </el-form-item>
            <el-form-item label="令牌" prop="token">
              <el-input v-model="form.token" placeholder="请输入令牌"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="submitForm">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo} from "@/api/system/wechatInfo";

export default {
  name: "Info",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微信公众号信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        priId: null,
        appId: null,
        secret: null,
        token: null,
        tenantId: null,
      },
      // 表单参数/system/wechat-info/1
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getWechatInfo()
  },
  methods: {
    /** 查询微信公众号信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        priId: null,
        appId: null,
        secret: null,
        token: null,
        tenantId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 获取配置 */
    getWechatInfo(){
      getInfo().then(response => {
        this.form = response.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除微信公众号信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有微信公众号信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportInfo(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
